/*
 * Session.h
 *
 *  Created on: 2013. 9. 14.
 *      Author: jjaehuny
 */

#ifndef PROJECTZ_SESSION_H_
#define PROJECTZ_SESSION_H_

#include <Dispatcher/Session.h>
#include <Network/Packet.h>

#include "NUtil/ThreadPool.h"

#include <stack>

namespace ProjectZ {

class User;

class Session  : public ::Dispatcher::Session
{
public:
	Session();
	virtual ~Session();

	virtual void	OnPacket();
	void			ResetUser() { _user = NULL; }
	int				SendPacket(::Network::Packet * pPacket, bool bStatus, bool bOneShot = false);
	int				SendPacketAsync(::Network::Packet * pPacket);

private:
	void 			onClose(::Network::Packet * pPacket);
	void			on_CS_REQ_SERVER_ADDR(::Network::Packet * pPacket);
	bool			on_CS_CONNECT(::Network::Packet * pPacket);
	bool			on_CS_RECONNECT(::Network::Packet * pPacket);
	void			OnLogoutGuildMember();
	void			work();
	void			workAsync();
	unsigned char calcCheckSum(char* pData, int len);

private:
	User *			_user;
	std::deque< ::Network::Packet *> _clsWaitAsyncSender;
	std::mutex 	_mutex_Async;

	std::deque< ::Network::Packet *> _clsWaitSyncSender;
	std::mutex 	_mutex_Sync;

	bool			_bClose;
};

} /* namespace ProjectZ */

#endif /* PROJECTZ_SESSION_H_ */
